package thread;

/**
 * 静态方法上如果使用synchronized，那么该方法一定是同步的.
 *
 * 静态方法上指定的锁对象为当前类对象，即class类的实例。
 * 在JVM中每个被加载的类都有
 */
public class SyncDemo3 {
    public static void main(String[] args) {
        Thread t1 = new Thread() {
            public void run() {
                Boo.domes();
            }
        };

        Thread t2 = new Thread() {
            public void run() {
                Boo.domes();
            }
        };
        t1.start();
        t2.start();
    }
}

class Boo {
    public synchronized static void domes() {
        try {
            Thread t = Thread.currentThread();
            System.out.println(t.getName() + ":正在执行dosome方法...");
            Thread.sleep(5000);
            System.out.println(t.getName() + ":执行dosome方法完毕!");
        } catch (InterruptedException e) {
        }
    }
}